﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form2 : Form
    {
        public int Choice;
        string tex;
        public Form1 father;
        public Form2()
        {
            InitializeComponent();
            Text = "添加信息";
        }
        public Form2(string s)
        {
            InitializeComponent();
            Text = "修改信息";
            tex = s;

        }


        private void Form2_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (Choice == 0)
            {
                try
                {
                    if (this.cbbtype.Text == "台式机")
                    {
                        txtBatt.Enabled = false;
                        Desk co = new Desk();
                        co.Type = Typ.台式机;
                        co.Model = txtModel.Text;
                        co.Band = txtBand.Text;
                        co.Cpu = txtCpu.Text;
                        co.Memory = txtMem.Text;
                        co.Disk = txtDisk.Text;
                        co.Screen = txtScreen.Text;
                        co.Box = txtBox.Text;
                        father.coms.Add(co);
                    }
                    else if (this.cbbtype.Text == "笔记本")
                    {
                        txtBox.Enabled = false;
                        Note co = new Note();
                        co.Type = Typ.台式机;
                        co.Model = txtModel.Text;
                        co.Band = txtBand.Text;
                        co.Cpu = txtCpu.Text;
                        co.Memory = txtMem.Text;
                        co.Disk = txtDisk.Text;
                        co.Screen = txtScreen.Text;
                        co.Battery = txtBatt.Text;
                        father.coms.Add(co);
                    }
                }
                catch
                {
                    MessageBox.Show("请输入电脑类型");
                }
                father.Bind(father.coms);
                this.Close();
            }
            else
            {
                for(int i=0;i<father.coms.Count;i++)
                {
                    if (father.coms[i].Model == tex)
                    {
                      
                           try
                {
                    if (this.cbbtype.Text == "台式机")
                    {
                        txtBatt.Enabled = false;
                        Desk co = new Desk();
                        co.Type = Typ.台式机;
                        co.Model = txtModel.Text;
                        co.Band = txtBand.Text;
                        co.Cpu = txtCpu.Text;
                        co.Memory = txtMem.Text;
                        co.Disk = txtDisk.Text;
                        co.Screen = txtScreen.Text;
                        co.Box = txtBox.Text;
                        father.coms.Add(co);
                    }
                    else if (this.cbbtype.Text == "笔记本")
                    {
                        txtBox.Enabled = false;
                        Note co = new Note();
                        co.Type = Typ.台式机;
                        co.Model = txtModel.Text;
                        co.Band = txtBand.Text;
                        co.Cpu = txtCpu.Text;
                        co.Memory = txtMem.Text;
                        co.Disk = txtDisk.Text;
                        co.Screen = txtScreen.Text;
                        co.Battery = txtBatt.Text;
                        father.coms.Add(co);
                    }
                }
                catch
                {
                    MessageBox.Show("请输入电脑类型");
                }
                           father.coms.Remove(father.coms[i]);
                    }
                }
                father.Bind(father.coms);
                this.Close();
            }
        }
    }
}
